package ai.people.netmon.msgsearch.controller;

import ai.people.netmon.framework.domain.jx.vo.SocialAccountCardReqVO;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.msgsearch.domain.entity.SocialAccountCard;
import ai.people.netmon.msgsearch.service.IJxSocialAccountCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * jx项目-5亿社交账号展示
 * @author LiGuanNan
 * @date 2022/6/30 17:48
 */
@RestController
@RequestMapping("/v1/social-account-card")
public class JxSocialAccountCardController {

    @Autowired
    @Qualifier("flElasticsearchRestTemplate")
    private ElasticsearchRestTemplate flElasticsearchRestTemplate;

    @Autowired
    private IJxSocialAccountCardService jxSocialAccountCardService;


    @PostMapping("/page")
    public Result<PageResponse<SocialAccountCard>> searchPage(@Validated @RequestBody SocialAccountCardReqVO reqVo){
        int maxPage ;
        if(reqVo.getIsAfricaAccount() == 0){
            maxPage = 10000/(reqVo.getPageSize()/5);
        }else {
            maxPage = 10000/(reqVo.getPageSize());
        }
        int current = reqVo.getOriginPageNo();
        reqVo.setCurrentPage(current);
        reqVo.setPageNo(reqVo.getOriginPageNo() <= maxPage ? reqVo.getOriginPageNo() : reqVo.getOriginPageNo() % maxPage < 100 ? reqVo.getOriginPageNo() % maxPage + 100 : reqVo.getOriginPageNo() % maxPage);
        PageResponse<SocialAccountCard> pageResponse = jxSocialAccountCardService.searchPageV2(reqVo);
        pageResponse.setCurrent((long) current);
        return new Result<>(pageResponse);
    }
}
